﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using AgilePlannerDT.Data;


namespace AgilePlannerDT.Persister.Impl.Socket
{
    public class XMLSocketClient : SocketConnectionEndpoint
    {
        protected static InboundConnection inbound;
        protected static OutboundConnection outbound;

        protected MessageSink ms;

        private IConnection connection;
        private long client_id;

        public XMLSocketClient(IConnection connection, MessageSink ms)
        {
            this.connection = connection;
            this.ms = ms;
            outbound = new OutboundConnection(connection, this);

        }

        public void Send(Message msg)
        {
            lock (this)
            {
                msg.Sender = client_id;
                outbound.Send(msg);
            }
        }

        public void Receive(Message msg)
        {
            ms.Receive(msg);
        }

        public void ShutDown()
        {
            outbound.close();
            connection.close();
        }

        public void SetID(long id)
        {
            client_id = id;
        }

    }
}
